// sudo npm install webpack html-webpack-plugin clean-webpack-plugin style-loader css-loader less-loader less url-loader file-loader vue vue-router vue-loader vue-template-compiler babel-loader babel-preset-es2015 babel-core   babel-plugin-transform-runtime 
// sudo npm install webpack-dev-server -g

var webpack = require("webpack");

//生成HTML
var html = require("html-webpack-plugin");
//删除文件
var clean = require("clean-webpack-plugin");
//压缩代码
var uglifyJsPlugin = webpack.optimize.UglifyJsPlugin;

module.exports = {
    entry:"./app/app.js",//入口文件
    output:{//输出地址
        //输出的文件夹名字
        path:__dirname+"/www",
        //输出的js文件名
        filename:"js/bundle.js"
    },
    module:{//模块
        loaders:[
            {   
                //css样式打包
                test:/\.css$/,
                loader:"style-loader!css-loader!less-loader"
            },
            {
                //图片打包
                test:"/\.(png|jpe?g|gif)$/",
                loader:"url-loader?limit=5000s&name=images/[name].[hash:4].[ext]"
            },
            {
                //vue打包
                test:/\.vue$/,
                loader:"vue-loader"
            }
        ]
    },
    //sudo npm install webpack-dev-server -g 全局安装
    //自动刷新 终端输入:webpack-dev-server
    devServer: {
      contentBase:"./www",
      inline: true,
      port: 8088
    },
    plugins:[//插件
        //生成html
        new html({
            title:"么么哒",//设置标题
            template:__dirname+"/app/index.html",//全局目录
            filename:"index.html",//文件名
        }),
        //先删除旧的www文件夹,在生成新的www文件夹
        new clean(["www"]),
        //压缩代码
        // new webpack.optimize.UglifyJsPlugin({
        //     compress:{
        //         warnings:false,//取消报错提示
        //     }
        // }),
    ],
    resolve:{
        alias:{
         "vue$": 'vue/dist/vue.common.js',
        }
    }
}